#ifndef __JZM_ENC_API_T10_H__
#define __JZM_ENC_API_T10_H__
#include <stdint.h>
#include <stdbool.h>

typedef uint32_t JZ_U32;
typedef uint8_t  JZ_U8;
typedef int8_t   JZ_BOOL;
typedef int8_t   JZ_S8;
typedef int32_t  JZ_S32;
typedef float    JZ_FL;

typedef enum{
    CBR   = 0,
    VBR   = 1,
    FIXQP = 2,
    SMART = 3
} VPU_RC_MODE_S;

typedef enum{
    DO_NOTHING      = 0,
    DROP_NEXT_FRM   = 1,
    PSKIP_NEXT_FRM  = 2
} VPU_RC_BitRateUpMode_S;

typedef enum{
    SF_DO_NOTHING   = 0,
    SF_DROP_CUR_FRM = 1,
    SF_RE_ENOCDE    = 2
} VPU_RC_SuperFrmMode_S;

typedef enum{
    SF_PR_NOTHING       = 0,
    SF_BITRATE_FIRST    = 1,
    SF_FRAMEBITS_FIRST  = 2
} VPU_RC_Priority_S;

typedef struct jzVPU_ATTR_H264_FIXQP_S {
    JZ_U32                    u32Gop;                 /* the interval of adjacent I frame */
    JZ_U8                     u8Fps;                  /* the num of encode frames per second */
    JZ_U8                     u8ConstQp;              /* given P frame qp */
    JZ_S8                     s8CqpIPDelta;           /* given I frame qp delta with P frame qp */
}VPU_ATTR_H264_FIXQP_S;

typedef struct jzVPU_ATTR_H264_CBR_S {
    JZ_U8                     u8Fps;                  /* the num of encode frames per second */
    JZ_U32                    u32Gop;                 /* the interval of adjacent I frame */
    JZ_U32                    u32TgtRate;             /* target bitrate */
}VPU_ATTR_H264_CBR_S;

typedef struct jzVPU_PARAM_H264_CBR_S {
    JZ_U8                     u8MaxQp;                /* set max allowed encode qp */
    JZ_U8                     u8MinQp;                /* set min allowed encode qp */
    JZ_U8                     u8QpMaxDelta;
    JZ_FL                     fNewQpMaxTrigLevel;
    JZ_S8                     s8IPQpDelta;
    JZ_U8                     u8FrmQpStep;            /* set adjacent P frame qp step */
    JZ_U8                     u8GopQpStep;            /* set gop qp step */
    JZ_S8                     s8IQpBias;
    JZ_BOOL                   bGopRelat;
}VPU_PARAM_H264_CBR_S;

typedef struct jzVPU_ATTR_H264_VBR_S {
    JZ_U8                     u8Fps;                   /* the num of encode frames per second */
    JZ_U8                     u8StatTime;
    JZ_U32                    u32MaxRate;              /* max target bits */
    JZ_U32                    u32Gop;                  /* the interval of adjacent I frame */
}VPU_ATTR_H264_VBR_S;

typedef struct jzVPU_PARAM_H264_VBR_S {
    JZ_U8                     u8MaxQp;
    JZ_U8                     u8MinQp;
    JZ_S8                     s8IQpBias;
    JZ_U8                     u8QpMaxDelta;
    JZ_FL                     fNewQpMaxTrigLevel;
    JZ_U8                     u8FrmQpStep;              /* set adjacent P frame qp step */
    JZ_U8                     u8GopQpStep;
    JZ_U8                     u8ChangePos;
    JZ_U8                     u8QualityLevel;
    JZ_U8                     u8SkipFrmGaps;            /* unuse */
    JZ_S8                     s8IPQpDelta;
    JZ_U32                    u32MinRate;               /* min target bitrate */
    JZ_U32                    u32MinIFrmBits;           /* unuse */
    JZ_U32                    u32SuperIFrmBitsThr;      /* super I frame encode bits threshold */
    JZ_U32                    u32SuperPFrmBitsThr;      /* super P frame encode bits threshold */
    JZ_U8                     u8MaxIprop;               /* unuse */
    JZ_U8                     u8MinIprop;               /* unuse */
    JZ_U8                     u8dropFrmNum;             /* unuse */
    JZ_U8                     u8PskipFrmNum;            /* unuse */
    JZ_U8                     u8ReEncTime;              /* set max reencode times */
    JZ_U8                     u8ReEncQpDelta;           /* unuse */
    JZ_FL                     fBeyondBitrateThr;        /* unuse */
    JZ_BOOL                   bGopRelat;
    JZ_BOOL                   bIsDropNextFrm;           /* unuse */
    JZ_BOOL                   bIsSkipNextFrm;           /* unuse */
    VPU_RC_SuperFrmMode_S     superFrmMode;
    VPU_RC_BitRateUpMode_S    bitRateUpMode;            /* unuse */
}VPU_PARAM_H264_VBR_S;

typedef struct jzVPU_ATTR_H264_SMART_S {
    JZ_U8                     u8Fps;                     /* the num of encode frames per second */
    JZ_U8                     u8StatTime;
    JZ_U32                    u32MaxRate;                /* max target bits */
    JZ_U32                    u32Gop;
}VPU_ATTR_H264_SMART_S;

typedef struct jzVPU_PARAM_H264_SMART_S {
    JZ_U8                     u8MaxQp;
    JZ_U8                     u8MinQp;
    JZ_S8                     s8IQpBias;
    JZ_U8                     u8QpMaxDelta;
    JZ_FL                     fNewQpMaxTrigLevel;
    JZ_U8                     u8FrmQpStep;
    JZ_U8                     u8GopQpStep;
    JZ_U8                     u8ChangePos;
    JZ_U8                     u8QualityLevel;
    JZ_U8                     u8SkipFrmGaps;               /* unuse */
    JZ_S8                     s8IPQpDelta;
    JZ_U32                    u32MinRate;
    JZ_U32                    u32MinIFrmBits;              /* unuse */
    JZ_U32                    u32SuperIFrmBitsThr;
    JZ_U32                    u32SuperPFrmBitsThr;
    JZ_U8                     u8MaxIprop;                  /* unuse */
    JZ_U8                     u8MinIprop;                  /* unuse */
    JZ_U8                     u8dropFrmNum;                /* unuse */
    JZ_U8                     u8PskipFrmNum;               /* unuse */
    JZ_U8                     u8ReEncTime;                 /* unuse */
    JZ_U8                     u8ReEncQpDelta;
    JZ_FL                     fBeyondBitrateThr;           /* unuse */
    JZ_BOOL                   bGopRelat;
    JZ_BOOL                   bIsDropNextFrm;              /* unuse */
    JZ_BOOL                   bIsSkipNextFrm;              /* unuse */
    VPU_RC_SuperFrmMode_S     superFrmMode;
    VPU_RC_BitRateUpMode_S    bitRateUpMode;               /* unuse */
}VPU_PARAM_H264_SMART_S;

typedef struct jzVPU_RC_S {
    VPU_RC_MODE_S             rcMode;                      /* rc mode : CBR, VBR, FIXQP, SMART */
    VPU_ATTR_H264_FIXQP_S     attrH264Fixqp;               /* FIXQP mode attribute parameter */
    VPU_ATTR_H264_CBR_S       attrH264Cbr;                 /* CBR mode attribut parametr */
    VPU_ATTR_H264_VBR_S       attrH264Vbr;                 /* VBR mode attribut parametr */
    VPU_ATTR_H264_SMART_S     attrH264Smart;               /* SMART mode attribut parametr */
    VPU_PARAM_H264_CBR_S      paramH264Cbr;                /* CBR mode high parametr */
    VPU_PARAM_H264_VBR_S      paramH264Vbr;                /* VBR mode high parametr */
    VPU_PARAM_H264_SMART_S    paramH264Smart;              /* SMART mode high parametr */
    JZ_U8                     VPUCoreNum;
    JZ_U8                     FrameQP;                     /* encode current frame qp */
    JZ_U8                     *Yplane;
    JZ_U8                     FrameType;
    JZ_U32                    PredMad;                     /* VPU return frame mad */
    JZ_U32                    ActualBits;                  /* VPU return frame actual bits */
    JZ_U32                    Ystride;
    JZ_U32                    MbWidth;                     /* MacroBlock number in horizontal of a frame */
    JZ_U32                    MbHeight;                    /* MacroBlock number in verticalof of a frame */
    JZ_U32                    FrmCnt;
    JZ_BOOL                   bIFrmReq;                    /*request encode I frame */
    void                      *RCptr0, *RCptr1;            /* Users don't care about its */
    JZ_S8                     isBigPFrame;
    JZ_U8                     u8ChgRefEn;
    JZ_U8                     ChangeRef;
} VPU_RC_S;

void JZ_VPU_RC_VIDEO_CFG(VPU_RC_S *rc);
void JZ_VPU_RC_FREE(VPU_RC_S *rc);
void JZ_VPU_RC_FRAME_RC(VPU_RC_S *rc);
int JZ_VPU_RC_FRAME_REPEATE_JUDGE(VPU_RC_S *rc);

#endif //__JZM_ENC_API_H__
